package com.bwie.es.controller;

import com.bwie.common.result.Result;
import com.bwie.es.domain.EsShop;
import com.bwie.es.domain.request.EsShopRequest;
import com.bwie.es.service.EsService;
import org.dromara.easyes.core.biz.EsPageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Es控制层
 *
 * @author <a href="mailto:2891704036@qq.com">zhiyuheng</a>
 * @version 1.0
 * @description: Es控制层
 * @date 2025/9/9 10:26
 */
@RestController
public class EsController {

    @Autowired
    private EsService esService;

    /**
     * 创建索引
     * @return
     */
    @PutMapping("createIndex")
    public Result createIndex(){
        esService.createIndex();
        return Result.success();
    }

    /**
     * 添加
     * @param esShop
     * @return
     */
    @PostMapping("add")
    public Result add(@RequestBody EsShop esShop){
        esService.add(esShop);
        return Result.success();
    }

    /**
     * 修改
     * @param esShop
     * @return
     */
    @PutMapping("update")
    public Result update(@RequestBody EsShop esShop){
        esService.update(esShop);
        return Result.success();
    }

    /**
     * 禁用
     * @return
     */
    @DeleteMapping("delete/{id}")
    public Result delete(@PathVariable("id") Long id){
        esService.delete(id);
        return Result.success();
    }

    /**
     * 店铺列表
     * @param request
     * @return
     */
    @PostMapping("pageList")
    public Result<EsPageInfo<EsShop>> pageList(@RequestBody EsShopRequest request){
        return Result.success(esService.pageList(request));
    }
}
